<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
  <script>
    var person =
      [{"id":1 , "name" :"aaa" , "age":80 , "fatherId" : null},
      {"id":2 , "name" :"bbb" , "age":79 , "fatherId" : null},
      {"id":3 , "name" :"ccc" , "age":50 , "fatherId" : 2},
      {"id":4 , "name" :"ddd" , "age":48 , "fatherId" : 2},
      {"id":5 , "name" :"eee" , "age":24 , "fatherId" : 3},
      {"id":6 , "name" :"fff" , "age":2 , "fatherId" : 5},
      {"id":7 , "name" :"ggg" , "age":52 , "fatherId" : 1},
      {"id":8 , "name" :"hhh" , "age":30 , "fatherId" : 2},
      {"id":9 , "name" :"iii" , "age":33 , "fatherId" : 1},
      {"id":10 , "name" :"jjj" , "age":41 , "fatherId" : 1},
      {"id":11 , "name" :"kkk" , "age":10 , "fatherId" : 9},
      {"id":12 , "name" :"lll" , "age":3 , "fatherId" : 10},
      {"id":13 , "name" :"mmm" , "age":60 , "fatherId" : null},
      {"id":14 , "name" :"nnn" , "age":40 , "fatherId" : 13},
      {"id":15 , "name" :"ooo" , "age":4 , "fatherId" : 15},
      {"id":16 , "name" :"ppp" , "age":15 , "fatherId" : 3},
      {"id":17 , "name" :"qqq" , "age":9 , "fatherId" : 14},
      {"id":18 , "name" :"rrr" , "age":66 , "fatherId" : null},
      {"id":19 , "name" :"sss" , "age":23 , "fatherId" : 18}]


    function fn1(id) {
      var arr = [];
      for( var key of person){
        if(key.fatherId == id){
          arr.push(key.id);
          console.log(key);
        }
      }
      for(var i=0;i<arr.length;i++){
        fn1(arr[i])
      }
    }

    fn1(3)

    // function fn2(id){
    //   for(var key of person){
    //     if(key.id == id) {
    //       for (var key2 of person) {
    //         if (key2.id == key.fatherId){
    //           console.log(key2);
    //           fn2(key2.id)
    //         }
    //       }
    //     }
    //   }
    // }
    //
    //
    // function fn(n){
    //   fn2(n)
    //   fn1(n)
    // }


  </script>
</body>
</html>